DovecotによるSASL化
 

概要:

 メールアカウントのパスワードとシステムアカウントのパスワードを別々に設定できるようにします。メールアカウントのパスワードが外部に漏れてもシステムアカウントとしてシステムにアクセスできないのでセキュリティーが向上します。PostfixとDovecotでパスワードを一元管理するためにDovecotのSMTP-Auth機能をPostfixとDovecotで使用するように設定します。
前章のPostfix + Dovecotのインストールから修正して設定します。初めからパスワードを別々に設定する場合は前章と合わせて設定して下さい。認証デーモンsaslauthdに関連する設定が変更・不要になります。
また、次章のバーチャルホストでもこの仕組みを使用します。

前提:

1. saslauthdの停止(起動していた場合)

# /etc/rc.d/init.d/saslauthd stop ← saslauthd停止
saslauthd を停止中:                                        [  OK  ]

# chkconfig saslauthd off ← saslauthd自動起動設定の取消し

2.Postfix

2.1 main.cfの設定

# vi /etc/postfix/main.cf
     :
  (省略)
     :
### SASL設定 ###
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_sasl_type = dovecot      ← 追加
smtpd_sasl_path = private/auth    ← 追加
     :
  (省略)
     :

2.2 Postfix再起動

# service postfix restart ← Postfix再起動
Stopping postfix: [  OK  ]
Starting postfix: [  OK  ]

3.Dovecot

3.1 10-master.confの設定

# cd /etc/dovecot/conf.d
# vi 10-master.conf
     :
  (省略)
     :
service auth {
  # auth_socket_path points to this userdb socket by default. It's typically
  # used by dovecot-lda, doveadm, possibly imap process, etc. Its default
  # permissions make it readable only by root, but you may need to relax these
  # permissions. Users that have access to this socket are able to get a list
  # of all usernames and get results of everyone's userdb lookups.
  unix_listener auth-userdb {
    #mode = 0600
    #user =
    #group =
  }

  # Postfix smtp-auth
  #unix_listener /var/spool/postfix/private/auth {
  #  mode = 0666
  #}
     ↓ 次のように2行を追加してコメントを外す。
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }

  # Auth process is run as this user.
  #user = $default_internal_user
}
     :
  (省略)
     :

3.2 10-auth.confの設定

# cd /etc/dovecot/conf.d
# vi 10-auth.conf
     :
  (省略)
     :
# Space separated list of wanted authentication mechanisms:
#   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
#   gss-spnego
# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login
  ↓ 次のようにcram-md5を追加する。
auth_mechanisms = cram-md5 plain login
     :
  (省略)
     :
# User database specifies where mails are located and what user/group IDs
# own them. For single-UID configuration use "static" userdb.
#
# <doc/wiki/UserDatabase.txt>

#!include auth-deny.conf.ext
#!include auth-master.conf.ext

!include auth-system.conf.ext
  ↓ コメントアウトする。
#!include auth-system.conf.ext
#!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
#!include auth-passwdfile.conf.ext
  ↓ コメントアウトを外す。
!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext

3.3 auth-passwdfile.conf.extの設定

パスワードを設定するファイルを設定します。ここでは/etc/dovecot/passwdとしています。ファイル名は適当に設定して下さい。

# cd /etc/dovecot/conf.d
# vi auth-passwdfile.conf.ext
# Authentication for passwd-file users. Included from auth.conf.
#
# passwd-like file with specified location.
# <doc/wiki/AuthDatabase.PasswdFile.txt>

passdb {
  driver = passwd-file
#  args = scheme=CRYPT username_format=%u /etc/dovecot/users  ← コメントアウトする。
  args = /etc/dovecot/passwd                                  ← 追加する。
}

userdb {
 driver = passwd-file
#  args = username_format=%u /etc/dovecot/users               ← コメントアウトする。
  args = /etc/dovecot/passwd                                  ← 追加する。
}

3.4 アカウントのパスワードの設定

上記auth-passwdfile.conf.extに設定したパスワードファイルにメールアカウントとパスワードを設定します。

  1. ) パスワードの生成
    パスワードはdoveadmコマンドで生成します。
    # doveadm pw -s HMAC-MD5
    Enter new password:      ← パスワードを入力
    Retype new password:     ← パスワードを確認のため再入力
    {HMAC-MD5}dd59f669267e9bb13d42a1ba57c972c5b13a4b2ae457c9ada8035dc7d8bae41b
    
  2. ) アカウントのpasswd情報
    アカウント(ここではアカウントcentos)のpasswd情報を調べます。
    # grep centos /etc/passwd
    centos:x:502:502::/home/centos:/bin/bash
    
  3. ) パスワードファイル設定
    パスワードファイルを設定します。上記のパスワードにあたるx部分に生成したパスワードを{HMAC-MD5}の部分を含めて記述します。uid、gid、Homeディレクトリーはメールを配信するために使用されます。シェル部分は設定しなくてもよいようです。以下ではadminとcentosの2つのシステムアカウントを設定しています。
    # vi /etc/dovecot/passwd
    
    admin:{HMAC-MD5}cb1dbd769e9bb1d42a1ba59de16a961edad51e4b2aef57c9ada8035d6547cce6:501:501::/home/admin
    centos:{HMAC-MD5}dd59f669267e9bb13d42a1ba57c972c5b13a4b2ae457c9ada8035dc7d8bae41b:502:502::/home/centos
    
  4. ) 因みにuid以降が無い場合、dovecotのログに以下のようなエラーが書かれます。
    Jan  1 01:01:01 imap(centos): Error: user centos: Couldn't drop privileges: User is missing UID (see mail_uid setting)
    Jan  1 01:01:01 imap(centos): Error: Internal error occurred. Refer to server log for more information.
    

3.5 Dovecot再起動

# service dovecot restart ← Dovecot再起動
Stopping dovecot Imap : [  OK  ]
Starting dovecot Imap : [  OK  ]
 
 

最終更新のRSS
Last-modified: 2014-03-11 (火) 02:00:03 (3702d)